package com.bush.mall.product.controller;

import com.bush.mall.product.entity.dto.BrandDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.bush.mall.common.entity.Result;
import com.bush.mall.product.entity.BrandEntity;
import com.bush.mall.product.service.BrandService;
import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 品牌
 * @author RUN
 * @date 2022-11-28
 */
@RestController
@RequestMapping("product/brand")
@Api(tags = "品牌管理" )
public class BrandController {

    @Resource(name= BrandService.BEAN_ID)
    private BrandService brandService;

    @ApiOperation(value = "分页查询品牌列表")
    @GetMapping("queryForPage")
    public Result queryForPage(BrandDTO dto){
        return brandService.queryForPage(dto);
    }

    @ApiOperation(value = "保存品牌")
    @PostMapping
    public Result saveBrand(@RequestBody @Validated BrandEntity brand){
        return brandService.saveBrand(brand);
    }

    @ApiOperation(value = "修改品牌")
    @PutMapping
    public Result updateBrand(@RequestBody @Validated BrandEntity brand){
        return brandService.updateBrand(brand);
    }

    @ApiOperation(value = "通过指定id删除品牌")
    @DeleteMapping("{id}")
    public Result deleteBrand(@PathVariable(value = "id") Long id){
        return brandService.deleteBrand(id);
    }

    @ApiOperation(value = "批量删除品牌")
    @DeleteMapping("batch")
    public Result deleteBatchBrand(@RequestBody List<Long> ids){
        return brandService.deleteBatchBrand(ids);
    }

    @ApiOperation(value = "更改是否显示品牌状态")
    @PatchMapping("show/{id}")
    public Result changeStatus(@PathVariable(value = "id") Long id){
        return brandService.changeStstua(id);
    }

}
